﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using mds.Common;
using System.IO;

namespace mds.Configuration
{
    public class ConfigurationReader
    {
        private static ConfigurationReader _instance = new ConfigurationReader();
        // private static Boolean _isDebug;
        public static ConfigurationReader Instance
        {
            get
            {
                return _instance;
            }
        }
        private bool TestDebug()
        {
            bool result = false;
            try
            {
                var isLocal = bool.Parse(System.Configuration.ConfigurationManager.AppSettings[ConfigurationDefine.DebugType]);
                if (isLocal)
                    result = true;
            }
            catch
            {
                result = false;
            }
            return result;
        }
        private string GetStartWorkPath()
        {
            string path = null;
            try
            {
                path = System.Configuration.ConfigurationManager.AppSettings[ConfigurationDefine.ConfigPath];

            }
            catch
            {
                path = "";
            }
            if (string.IsNullOrEmpty(path))
                path = path + @"\";
            return path;
        }
        internal List<T> ReadConfigs<T>(string fileName)
        {
            string filePath = GetStartWorkPath() + fileName + ".xml";
            return XmlConfigSerializer.Instance.Deserialize<T>(filePath);
        }
        internal T ReadForSingle<T>(string fileName)
        {
            string filePath = GetStartWorkPath() + fileName + ".xml";
            return XmlConfigSerializer.Instance.DeserializeSingle<T>(filePath);
        }
        internal bool Exists(string fileName)
        {
            string filePath = GetStartWorkPath() + fileName + ".xml";
            return File.Exists(filePath);
        }
    }
}
